package com.hz.zbl.mapper;

import com.hz.zbl.model.dto.UserSelectCourseDTO;
import com.hz.zbl.model.entity.UserCourseEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserCourseMapper {


    //添加学生选课记录
    @Insert("INSERT INTO user_courses VALUES (null, #{course_name}, #{course_code}, #{student_user_id}, #{teacher_user_id}, #{student_realname}, #{teacher_realname}, #{user_score}, #{course_id}, #{course_year}, #{course_semester}, #{course_room}, #{current_section_count})")
    int addUserCourse(UserCourseEntity userCourseEntity);



    //通过课程代码和学生id查找选课
    @Select("SELECT * FROM user_courses WHERE course_code = #{course_code} AND student_user_id = #{student_user_id}")
    UserCourseEntity selectByCourseIdAndStudentId(@Param("student_user_id") int student_user_id, @Param("course_code") String course_code);

    @Select("SELECT * FROM user_courses WHERE course_name = #{course_name} AND student_user_id = #{student_user_id}")
    UserCourseEntity selectByCourseNameAndStudentId(@Param("course_name") String course_name, @Param("student_user_id") int student_user_id);

    //通过课程代码和学生id删除课程
    @Delete("DELETE FROM user_courses WHERE student_user_id = #{student_user_id} AND course_code = #{course_code}")
    int deleteUserCourse(@Param("student_user_id") int student_user_id, @Param("course_code") String course_code);


    //更新学生选课成绩
    @Update("UPDATE user_courses SET user_score = #{user_score} WHERE student_user_id = #{student_user_id} AND course_code = #{course_code}")
    int updateUserCourse(@Param("user_score") int user_score, @Param("student_user_id") int student_user_id, @Param("course_code") String course_code);


    //查看学生所选课程
    @Select("SELECT * FROM user_courses WHERE student_user_id = #{student_user_id}")
    List<UserCourseEntity> selectedCourses(@Param("student_user_id") int student_user_id);


    //通过课程代码查看所选该课程的记录
    @Select("SELECT * FROM user_courses WHERE course_code = #{course_code}")
    List<UserCourseEntity> courseInfo(@Param("course_code") String course_code);

    //学生选择学年查看课表
    @Select("SELECT * FROM user_courses WHERE student_user_id = #{student_user_id} AND course_year = #{course_year}")
    List<UserCourseEntity> studentYearSchedule(@Param("student_user_id") int student_user_id, @Param("course_year") int course_year);


    //学生选择学年学期查看课表
    @Select("SELECT * FROM user_courses WHERE student_user_id = #{student_user_id} AND course_year = #{course_year} AND course_semester = #{course_semester}")
    List<UserCourseEntity> studentSemesterSchedule(@Param("student_user_id") int student_user_id, @Param("course_year") int course_year, @Param("course_semester") int course_semester);


    //查看教师所教课程
    @Select("SELECT * FROM user_courses WHERE teacehr_user_id = #{teacher_user_id}")
    List<UserCourseEntity> teacherCourses(@Param("teacher_user_id") int teacher_user_id);


    //教师查看学年课表
    @Select("SELECT * FROM user_courses WHERE teacher_user_id = #{teacher_user_id} AND course_year = #{course_year}")
    List<UserCourseEntity> teacherYearSchedule(@Param("teacher_user_id") int teacher_user_id, @Param("course_year") int course_year);

    //教师查看学年学期课表
    @Select("SELECT * FROM user_courses WHERE teacher_user_id = #{teacher_user_id} AND course_year = #{course_year} AND course_semester = #{course_semester}")
    List<UserCourseEntity> teacherSemesterSchedule(@Param("teacher_user_id") int teacher_user_id, @Param("course_year") int course_year, @Param("course_semester") int course_semester);

    //查看指定课程包含学生人数
    @Select("SELECT COUNT(*) FROM user_courses WHERE course_name = #{course_name}")
    int courseStudentCount(@Param("course_name") String course_name);
}
